﻿namespace UnityEditor.Utils
{
    using System;
    using System.Runtime.CompilerServices;
    using UnityEditor;
    using UnityEngine;

    internal class PerformanceChecks
    {
        private static string[] kShadersWithMobileVariants = new string[] { "VertexLit", "Diffuse", "Bumped Diffuse", "Bumped Specular", "Particles/Additive", "Particles/VertexLit Blended", "Particles/Alpha Blended", "Particles/Multiply", "RenderFX/Skybox" };

        public static string CheckMaterial(Material mat, BuildTarget buildTarget)
        {
            <CheckMaterial>c__AnonStorey4B storeyb = new <CheckMaterial>c__AnonStorey4B();
            Shader s = mat.shader;
            if (s != null)
            {
                storeyb.shaderName = s.name;
                int lOD = ShaderUtil.GetLOD(s);
                bool flag = Array.Exists<string>(kShadersWithMobileVariants, new Predicate<string>(storeyb.<>m__A3));
                bool flag2 = IsMobileBuildTarget(buildTarget);
                if ((buildTarget == BuildTarget.Android) && ShaderUtil.HasClip(mat.shader))
                {
                    return FormattedTextContent("PerformanceChecks.ShaderWithClipAndroid", new string[0]);
                }
                if (flag)
                {
                    if ((flag2 && mat.HasProperty("_Color")) && (mat.GetColor("_Color") == new Color(1f, 1f, 1f, 1f)))
                    {
                        string[] args = new string[] { "Mobile/" + storeyb.shaderName };
                        return FormattedTextContent("PerformanceChecks.ShaderUsesWhiteColor", args);
                    }
                    if (flag2 && storeyb.shaderName.StartsWith("Particles/"))
                    {
                        string[] textArray2 = new string[] { "Mobile/" + storeyb.shaderName };
                        return FormattedTextContent("PerformanceChecks.ShaderHasMobileVariant", textArray2);
                    }
                    if (((storeyb.shaderName == "RenderFX/Skybox") && mat.HasProperty("_Tint")) && (mat.GetColor("_Tint") == new Color(0.5f, 0.5f, 0.5f, 0.5f)))
                    {
                        string[] textArray3 = new string[] { "Mobile/Skybox" };
                        return FormattedTextContent("PerformanceChecks.ShaderMobileSkybox", textArray3);
                    }
                }
                if (((lOD >= 300) && flag2) && !storeyb.shaderName.StartsWith("Mobile/"))
                {
                    return FormattedTextContent("PerformanceChecks.ShaderExpensive", new string[0]);
                }
                if (storeyb.shaderName.Contains("VertexLit") && mat.HasProperty("_Emission"))
                {
                    Color color = mat.GetColor("_Emission");
                    if (((color.r >= 0.5f) && (color.g >= 0.5f)) && (color.b >= 0.5f))
                    {
                        return FormattedTextContent("PerformanceChecks.ShaderUseUnlit", new string[0]);
                    }
                }
                if (mat.HasProperty("_BumpMap") && (mat.GetTexture("_BumpMap") == null))
                {
                    return FormattedTextContent("PerformanceChecks.ShaderNoNormalMap", new string[0]);
                }
            }
            return null;
        }

        private static string FormattedTextContent(string localeString, params string[] args)
        {
            return string.Format(EditorGUIUtility.TextContent(localeString).text, (object[]) args);
        }

        private static bool IsMobileBuildTarget(BuildTarget target)
        {
            return ((target == BuildTarget.iPhone) || (target == BuildTarget.Android));
        }

        [CompilerGenerated]
        private sealed class <CheckMaterial>c__AnonStorey4B
        {
            internal string shaderName;

            internal bool <>m__A3(string s)
            {
                return (s == this.shaderName);
            }
        }
    }
}

